#------------------------------------字典和结构化数据
#5.1 字典数据类型
#键、值对、索引（可以采用各种数据类型）

# myCat = {'size':'cat',208:'gray','disposition':'loud'}
# print(myCat['size'])
# print('My cat has '+myCat[208]+' fur.')

#5.1.1 字典与列表
#字典中的项不需要考虑排序
# spam = ['cat','dog']
# list = ['dog','cat']
# print(spam == list)
# myCat = {'size':'cat',208:'gray','disposition':'loud'}
# myDog = {208:'gray','size':'cat','disposition':'loud'}
# print(myCat == myDog)

#生日记录程序
# birthday = {'HZL':'Dec 10','LSJ':'Aug 16'}
# while True:
#     print('Enter a name:(blank to quit)')
#     name = input()
#     if name == ' ':
#         break

#     if name in birthday:
#         print(birthday[name] + ' is the birthday of '+name)
#     else:
#         print('There is no record for '+name)
#         print('When is the birthday?')
#         newday = input()
#         birthday[name] = newday
#         print('The data of new birthday updated')

#5.1.2 keys(),values(),items()
# spam = {'color':'red','age':42}
# for v in spam.values():
#     print(v)

# for k in spam.keys():
#     print(k)

# for i in spam.items():
#     print(i)

# print(list(spam.keys()))

#5.1.3 检查字典中是否存在键或值—— ——in & not in

#5.1.4 get()方法
# picnicItems = {'apples':5,'cups':2}
# print('I am bringing '+str(picnicItems.get('cups'))+' cups')
# print('I am bringing '+str(picnicItems.get('eggs'))+' cups')

#5.1.5 setdefault方法
# spam = {'name':'Hzl','age':5}
# spam.setdefault('color','blue')
# print(spam)
# spam.setdefault('color','white')
# print(spam)

#计算一个字符串中每个字符出现的次数
# message = 'Rupture directivity effects on strong ground motion during the 15 April'
# count = {}
# for character in message:
    # count.setdefault(character,0)
    # count[character] = count[character] + 1

# print(count)

#--------------------------------------5.2 美观地输出
# import pprint
# pprint.pprint(count)

#--------------------------------------5.3 使用数据结构对真实世界建模
#代数记谱法

#5.3.1 井字棋盘
theBoard = {'top-L':' ','top-M':' ','top-R':' ',
            'mid-L':' ','mid-M':' ','mid-R':' ',
            'low-L':' ','low-M':' ','low-R':' '}

def printBoard(board):
    print(board['top-L']+'|'+board['top-M']+'|'+board['top-R'])
    print('-----')
    print(board['mid-L']+'|'+board['mid-M']+'|'+board['mid-R'])
    print('-----')
    print(board['low-L']+'|'+board['low-M']+'|'+board['low-R'])

turn = 'X'
for i in range(9):
    printBoard(theBoard)
    print('Turn for '+turn+'.Move on which space?')
    move = input()
    theBoard[move] = turn
    if turn == 'X':
        turn = '0'
    else:
        turn = 'X'

printBoard(theBoard)

